package com.fafi.rxjava2.operator;

import com.fafi.rxjava1.subscribeon.Switcher;
import com.fafi.rxjava2.Callee;
import com.fafi.rxjava2.CallerOnCall;
import com.fafi.rxjava2.observeon.nobackpress.CallerCallbackOn;
import com.fafi.rxjava2.transform.noback.CallerConverter;

public abstract class Caller<T> {
    public static <T> Caller<T> create(CallerOnCall<T> callerOnCall) {
        return new CallerCreate<>(callerOnCall);
    }

    public void call(Callee<T> callee) {
        callActual(callee);
    }

    protected abstract void callActual(Callee<T> callee);

    public <R> Caller<R> lift(CallerOperator<R, T> operator) {
        return new CallerLift<>(this, operator);
    }

    public <R> Caller<R> map(Function<T, R> function) {
        return new CallerMap<>(this, function);
    }

    public com.fafi.rxjava2.operator.Caller<T> callOn(Switcher switcher) {
        return new com.fafi.rxjava2.subscribeon.nobackpress.CallerCallOn<>(this, switcher);
    }

    public Caller<T> callbackOn(Switcher switcher) {
        return new CallerCallbackOn<>(this, switcher);
    }

    public <R> Caller<R> unify(CallerConverter<T,R> callerConverter){
        return callerConverter.convert(this);
    }
}
